<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Request;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     */
    public function index()
    {
        $this->success('请求成功');
    }

    public function getshow()
    {

        //1 版本  0  隐藏
        $this->success('请求成功',['show'=>1]);
    }

    /**
     * @return void
        地址信息
     */
    public function getaddress(){

        $address=Db::name('address')->select();

        $this->success('地址信息',$address);

    }


    /**
     * 幻灯片
     */
    public function getbanner(){

        $banner=Db::name('aabanner')->select();

        foreach ($banner as&$key){

            $key['image']=cdnurl($key['image'],true);

        }

        $this->success('幻灯片',$banner);
    }

    /**
     * 分类
     */

    public function getmenus(){
        $banner=Db::name('types')->order('weigh desc')->select();

        foreach ($banner as&$key){

            $key['image']=cdnurl($key['image'],true);

        }

        $this->success('分类',$banner);

    }


    /**
     * 标签
     */

    public function geticons(){

        $banner=Db::name('icons')->order('id desc')->select();
        $this->success('标签',$banner);

    }

    /**
     * 首页推荐的信息
     */
    public function getindexshowbycity(){

        $city=$this->request->param('city');

        $addre=Db::name('address')->where(['name'=>$city])->find();

        if ($city){
            $map['address_id']=['eq',$addre['id']];
        }
        $map['status']=['eq','1'];
        $map['top']=['eq','1'];


        $banner=Db::name('land')
            ->where($map)->order('id desc')
            ->limit('20')->select();




        foreach ($banner as&$key){

            $key['image']=cdnurl($key['image'],true);

        }

        $this->success('首页推荐的信息',$banner);


    }

    /**
    全局设置
     */
        public function getseting(){

            $info=Db::name('aaseting')->where(['id'=>1])->find();

            $this->success('全局设置',$info);


        }

        /**
         * 获取信息
         */
        public function getnews(){

            $page=$this->request->param('page');
            $limits=($page-1)*10 .  ','. 10;


            $map['status']=['eq','1'];
            $map['tj']=['eq','1'];
            $list=Db::name('news')
                ->where($map)
                ->limit($limits)
                ->order('weigh desc')
                ->select();


            foreach ($list as&$key){

                $key['image']=cdnurl($key['image'],true);
                $key['datetime']=date('Y-m-d H:i',$key['datetime']);
            }

            $this->success('获取信息',$list);




        }



    /**
     * 获取信息
     */
    public function getnewss(){

        $page=$this->request->param('page');
        $limits=($page-1)*10 .  ','. 10;


        $map['status']=['eq','1'];

        $list=Db::name('news')
            ->where($map)
            ->limit($limits)
            ->order('weigh desc')
            ->select();


        foreach ($list as&$key){

            $key['image']=cdnurl($key['image'],true);
            $key['datetime']=date('Y-m-d H:i',$key['datetime']);
        }

        $this->success('获取信息',$list);




    }


    /**
     * 文章详情
     */

    public function getatriclebyid()
    {
        $id=$this->request->param('id');


        $list=Db::name('news')
            ->where('id','eq',$id)
            ->find();

        Db::name('news')->where('id','eq',$id)->setInc('see');

        $this->success('文章详情',$list);

    }

    /**
     * 全部商品
     */
    public function getallland(){

        $page=$this->request->param('page');
        $limit=($page-1)*10 . ', 10';

        $map['status']=['eq','1'];


        $use_id=$this->request->param('use_id');
        if (intval($use_id)){
            $map['utypes']=['eq',$use_id];
        }

        $icons_id=$this->request->param('icons_id');
        if (intval($icons_id)){
            $map['icons_id']=['eq',$icons_id];
        }

        $address_id=$this->request->param('address_id');
        if (intval($address_id)){
            $map['address_id']=['eq',$address_id];
        }

        $menuid=$this->request->param('menuid');
        if (intval($menuid)){
            $map['types_id']=['eq',$menuid];
        }



        $banner=Db::name('land')
            ->where($map)->order('id desc')
            ->limit($limit)->select();


        foreach ($banner as&$key){

            $key['image']=cdnurl($key['image'],true);

            $add=Db::name('address')->where(['id'=>$key['address_id']])->find();

            $key['address_sname']=$add['name'];


            $icon=Db::name('icons')->where(['id'=>$key['icons_id']])->find();

            $key['icons_sname']=$icon['name'];
        }

        $this->success('首页推荐的信息',$banner);

    }


    public function getindexshowbytitle(){

        $title=$this->request->param('title');

        if ($title){
            $map['name']=['like','%'.$title.'%'];
        }
        $map['status']=['eq','1'];
        $banner=Db::name('land')
            ->where($map)->order('id desc')
            ->select();

        foreach ($banner as&$key){
            $key['image']=cdnurl($key['image'],true);

        }

        $this->success('首页推荐的信息',$banner);


    }



    public function getmessage(){

        $list=Db::name('message')->order('weigh desc,id desc')->select();

        foreach ($list as&$key){
            $key['createtime']=date('Y-m-d H:i',$key['createtime']);

        }

        $this->success('信息',$list);

    }

    public function getmessagebyid(){

        $id=$this->request->param('id');


        $list=Db::name('message')->where(['id'=>$id])->find();


        $list['createtime']=date('Y-m-d H:i',$list['createtime']);



        $this->success('信息',$list);
    }


    //金额设置
    public function getmoneyset(){

        $list=Db::name('moneyset')->find();

        $this->success('信息',$list);
    }




    /**
     * 发布详情
     */
    /**
     * @return Auth
     */
    public function getinfobyid(){


        $id=$this->request->param('id');
        $info=Db::name('land')->where(['id'=>$id])->find();

        if (!$info['times']){

            Db::name('land')->where(['id'=>$id])->update(['times'=>time()]);
        }
        $info=Db::name('land')->where(['id'=>$id])->find();
        $show=0;


        Db::name('land')->where(['id'=>$id])->setInc('seecount');


        $image=explode(',',$info['images']);

        foreach ($image as $key=>$v){
            $image[$key]=cdnurl($v,true);
        }

        $info['image']=cdnurl($info['image'],true);

        $info['images']=$image;
        $info['show']=$show;
        $info['sc']=0;
        $info['times']=date('Y-m-d H:i',$info['times']);

        $info['mobile_v']=substr($info['landlordmobile'],0,4).'****'.substr($info['landlordmobile'],7,11);

        $this->success('用户详情',$info);



    }



}
